package com.after.saas.common.config;

import cn.hutool.json.JSONUtil;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.util.StringUtils;

import java.lang.reflect.Method;
import java.util.Collection;

/**
 * @Classname CustomKeyGenerator
 * @Description TODO
 * @auth after
 * @since 2022/11/27 15:32
 */
public class CustomKeyGenerator implements KeyGenerator {
    @Override
    public Object generate(Object target, Method method, Object... params) {
        if (params[0] instanceof Collection) {
            Collection collection  = JSONUtil.parseArray(params[0]);
            return String.join("_", collection);
        }
        return StringUtils.arrayToDelimitedString(params, "_");
    }
}
